package com.hyj.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyj.mapper.MessagesMapper;
import com.hyj.entity.Askers;
import com.hyj.entity.Fenye;
import com.hyj.entity.Messages;
import com.hyj.entity.Students;
import com.hyj.service.AskersService;
import com.hyj.service.StudentService;
import com.hyj.service.UsersService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2020-06-04
 */

@Controller
public class AskersController {
	@Autowired
	private Fenye fenye;
	@Autowired
	private AskersService askersService;
	@Autowired
	private StudentService studentService;
	@Autowired
	private UsersService usersService;
	@Autowired
	private MessagesMapper messagesmapper;
	//分页查询所有用户信息
	@RequestMapping(value = "getAskerAlls", method = RequestMethod.POST)
	@ResponseBody
	public Fenye<Askers> getAskerAlls(Integer page, Integer rows,Askers askers) {
		fenye.setPage((page - 1) * rows);
		fenye.setPageSize(rows);
		fenye.setAskers(askers);
		fenye = askersService.selectAllAskers(fenye);
		return fenye;
	}
	//修改员工分量的信息
	@RequestMapping(value = "updateWeight", method = RequestMethod.POST)
	@ResponseBody
	public Integer updateWeight(Askers askers) {

		return askersService.updateWeights(askers);
	}
	//查询所有学生
	@RequestMapping(value="getStuAll",method=RequestMethod.POST)
	@ResponseBody
	public Fenye getStuAll(Students student){
		fenye = studentService.selectStuAll();
		return fenye;
		
	}
	//查询所有用户
	@RequestMapping(value="getempAll",method=RequestMethod.POST)
	@ResponseBody
	public Fenye getempByUid(){
		
		return usersService.selectAllEmp();
	}
	//分配学生给对应的用户netPusherId
	@RequestMapping(value="updateStuNetIdById",method=RequestMethod.POST)
	@ResponseBody
	public Integer updateStuNetIdById(Students student,String uid){
		
		/*动态弹框*/
		Messages messages=new Messages();
		messages.setSid(student.getId());
		messages.setUid(Integer.parseInt(uid));
		
		messagesmapper.AddMessage(messages);
		
		fenye.setStudent(student);
		return studentService.updateStu(student);
		
	}
}
